<template>
  <div class="app-container">
    <transition name="fade-transform" mode="out-in">
      <div class="project-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px" class="search-form">
          <el-select v-model="queryParams.packageType" placeholder="请输入套餐类型">
            <el-option
              v-for="item in option"
              :key="item.id"
              :label="item.packageName"
              :value="item.id">
            </el-option>
          </el-select>
          &nbsp;
          <el-form-item label="套餐名称" prop="projectName">
            <el-input
              v-model="queryParams.projectName"
              placeholder="请输入套餐名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8 action-row">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['system:project:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['system:project:edit']"
            >修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['system:project:remove']"
            >删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['system:project:export']"
            >导出</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table
          v-loading="loading"
          :data="projectList"
          @selection-change="handleSelectionChange"
          class="custom-table"
          :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
          :row-style="{height:'50px'}"
          :cell-style="{padding:'8px 0'}"
        >
          <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键id" align="center" prop="id" />-->
          <el-table-column label="套餐ID" align="center" prop="projectId" />
          <el-table-column label="套餐名称" align="center" prop="projectName" width="150"/>
          <el-table-column label="照片" align="center" prop="projectImage" width="100">
            <template slot-scope="scope">
              <image-preview :src="scope.row.projectImage" :width="50" :height="50"/>
            </template>
          </el-table-column>
          <el-table-column label="套餐类型" align="center" prop="packageTypeName" width="150"/>
          <el-table-column label="院区" align="center" prop="easeName" />
          <el-table-column label="套餐价格" align="center" prop="projectPrice" width="80"/>
          <el-table-column label="套餐项目" align="center" width="450px">
            <template slot-scope="scope">
              <el-tag v-for="item in scope.row.exanName" :key="item">{{ item }}</el-tag>
            </template>
          </el-table-column>
          <!--      <el-table-column label="套餐介绍" align="center" prop="project" width="120"/>-->
<!--      <el-table-column label="注意事项" align="center" prop="precation" />-->
          <el-table-column label="状态" align="center" prop="status" >
            <template slot-scope="scope">
            <span v-if="scope.row.status === 1">
              <el-button type="success" icon="el-icon-check" circle></el-button>
            </span>
              <span v-else>
              <el-button type="danger" icon="el-icon-close" circle></el-button>
            </span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['system:project:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:project:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
          class="pagination-container"
        />

        <!-- 添加或修改体检套餐对话框 -->
        <el-dialog
          :title="title"
          :visible.sync="open"
          width="500px"
          append-to-body
          :close-on-click-modal="false"
          class="custom-dialog"
        >
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item label="套餐ID" prop="projectId">
              <el-input v-model="form.projectId" placeholder="请输入套餐ID" />
            </el-form-item>
            <el-form-item label="套餐名称" prop="projectName">
              <el-input v-model="form.projectName" placeholder="请输入套餐名称" />
            </el-form-item>
            <el-form-item label="照片" prop="projectImage">
              <image-upload v-model="form.projectImage"/>
            </el-form-item>
            <el-form-item label="适用院区" prop="easeId">
<!--          <el-input v-model="form.easeId" placeholder="请输入所属院区" />-->
              <el-select v-model="form.easeId" placeholder="医院院区">
                <el-option
                  v-for="item in options"
                  :key="item.id"
                  :label="item.address"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="套餐类型" prop="projectPrice">
              <el-select v-model="form.packageType" placeholder="套餐类型">
                <el-option
                  v-for="item in option"
                  :key="item.id"
                  :label="item.packageName"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="套餐项目" prop="projectPrice">
              <el-select
                v-model="form.examUpdateByID"
                placeholder="Select"
                style="width: 240px"
                clearable
                multiple
              >
                <template #label="{ label, value }">
                  <span>{{ label }}: </span>
                  <span style="font-weight: bold">{{ value }}</span>
                </template>
                <el-option
                  v-for="item in optio"
                  :key="item.exId"
                  :label="item.exName"
                  :value="item.exId"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="套餐价格" prop="projectPrice">
              <el-input v-model="form.projectPrice" placeholder="请输入套餐价格" />
            </el-form-item>
            <el-form-item label="套餐介绍" prop="project">
              <el-input v-model="form.project" placeholder="请输入套餐介绍" />
            </el-form-item>
            <el-form-item label="注意事项" prop="precation">
              <el-input v-model="form.precation" placeholder="请输入注意事项" />
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>
      </div>
    </transition>
  </div>
</template>

<script>
import { listProject, getProject, delProject, addProject, updateProject } from "@/api/system/project"
import {getlist} from "@/api/system/area";
import {getExamPackageName, listPackage} from "@/api/system/package";
import {ExamintionsProjectName, listExamintions} from "@/api/system/examintions";

export default {
  name: "Project",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 体检套餐表格数据
      projectList: [],
      options: [],
      option: [],
      optio: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        packageType:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询体检套餐列表 */
    getList() {
      this.loading = true
      listProject(this.queryParams).then(response => {
        this.projectList = response.rows
        this.total = response.total
        this.loading = false
      })
      getlist().then(res=>{
        this.options = res.data
      })
      getExamPackageName().then(res=>{
        this.option = res.data
      })
      ExamintionsProjectName().then(res=>{
        this.optio = res.data
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectId: null,
        projectName: null,
        projectImage: null,
        packageType: null,
        easeId: null,
        projectPrice: null,
        project: null,
        precation: null,
        // exanName:'',
        examUpdateByID:'',
        status: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加体检套餐"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getProject(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改体检套餐"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProject(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addProject(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除体检套餐编号为"' + ids + '"的数据项？').then(function() {
        return delProject(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/project/export', {
        ...this.queryParams
      }, `project_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

<style lang="scss" scoped>
.project-container {
  padding: 20px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
}

.search-form {
  margin-bottom: 20px;
  padding: 20px;
  background: #f5f7fa;
  border-radius: 4px;
}

.action-row {
  margin-bottom: 20px;

  .el-button {
    margin-right: 10px;
    transition: all 0.3s;

    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 2px 8px rgba(0,0,0,.15);
    }
  }
}

.custom-table {
  margin-bottom: 20px;

  ::v-deep .el-table__row {
    transition: all 0.3s;

    &:hover {
      background-color: #f5f7fa;
      transform: scale(1.01);
    }
  }

  .el-tag {
    margin: 2px;
    transition: all 0.3s;

    &:hover {
      transform: scale(1.1);
    }
  }
}

.pagination-container {
  text-align: right;
  margin-top: 20px;
}

.custom-dialog {
  ::v-deep .el-dialog__body {
    padding: 20px 30px;
  }

  .el-form-item {
    margin-bottom: 22px;
  }
}

// 页面切换动画
.fade-transform-enter-active,
.fade-transform-leave-active {
  transition: all 0.5s;
}

.fade-transform-enter {
  opacity: 0;
  transform: translateX(-30px);
}

.fade-transform-leave-to {
  opacity: 0;
  transform: translateX(30px);
}

// 按钮动画
.el-button {
  position: relative;
  overflow: hidden;

  &::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    background: rgba(255,255,255,.5);
    opacity: 0;
    border-radius: 100%;
    transform: scale(1, 1) translate(-50%);
    transform-origin: 50% 50%;
  }

  &:active::after {
    animation: ripple 0.6s ease-out;
  }
}

@keyframes ripple {
  0% {
    transform: scale(0, 0);
    opacity: 0.5;
  }
  100% {
    transform: scale(20, 20);
    opacity: 0;
  }
}
</style>
